package com.huike.web.controller.clues;

import com.alibaba.excel.EasyExcel;
import com.huike.clues.domain.vo.TbClueExcelVo;
import com.huike.clues.service.ITbClueService;
import com.huike.clues.utils.easyExcel.ExcelListener;
import com.huike.common.annotation.Log;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @version 1.0
 * @description 说明
 * @package com.huike.web.controller.clues
 */
@RestController
public class TbImportClueController {

    @Autowired
    private ITbClueService tbClueService;

    /**
     * 上传线索
     * @param file
     * @return
     * @throws Exception
     */
    @Log(title = "上传线索", businessType = BusinessType.IMPORT)
    @PostMapping("/api/clues/clue/importData")
    public AjaxResult importData(MultipartFile file) throws Exception {
        ExcelListener excelListener = new ExcelListener(tbClueService);
        EasyExcel.read(file.getInputStream(), TbClueExcelVo.class, excelListener).sheet().doRead();
        return AjaxResult.success(excelListener.getResult());
    }
}
